<?php
 /***************************************************************
 * Mor-MVC Framework, A framework that can easily let you build a powerful
 * and scalable web application based on PHP language,
 * this framewrok is a copy of the Zend Behavior Framework
 *  Copyright (C) 2010  Nabil Droussi <nabildroussi@gmail.com>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ***************************************************************/
require_once("DBAdapter.php");
abstract class DataAccess
{
    private $_tableFields = array();
    protected $_adapter = null;
    private $_primaryKey = NULL;
    protected $_name = "";
    public function getFieldsTable()
    {
        return $this->_tableFields;
    }
    protected abstract function selectRaw($query,$where=null, $order=null, $group=null, $limit=null, $stack=null);
    protected abstract function select($where=null, $order=null, $group=null, $limit=null, $stack=null);
    protected abstract function selectJoin($fields,$tables,$where=null,$order=null,$group=null,$limit=null,$stack=null);
    protected abstract function insert();
    protected abstract function update();
    protected abstract function delete($where=NULL);
    protected function getSchema()
    {
        $query = "describe `{$this->_name}`";
        $result = $this->_adapter->query($query);
        if($result != NULL)
        {
            while($row = $result->fetchRow())
            {
                $this->{$row->Field} = NULL;
                $this->_tableFields[] = $row->Field;
                if(isset($row->Key) && $row->Key == "PRI")
                  $this->_primaryKey = $row->Field;
            }
        }
    }
    protected function getAdapter()
    {
        return $this->_adapter;
    }
    protected function executeQuery($query)
    {
        return $this->_adapter->query($query);
    }
    protected function getPrimaryKeyField()
    {
        return $this->_primaryKey;
    }
}